package com.wdh.kjs.activity;

import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel_my;
import com.wdh.kjs.util.ToastUtils;

import java.math.BigDecimal;

/**
 * Created by CQH on 2016/4/28.
 */
public class PlatformIntroActivity extends BaseTopActivity {
    private WebView introduce;
    private TextView mission;
    private TextView mission_content;
    private TextView hope;
    private TextView hope_content;
    private TextView value;
    private TextView value_content;
    private JsonModel_my jsonModel_my;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.platform_introduce);
        initview();
        loadData();
    }

    private void loadData() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("sign", "1");

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_PLATFORM_INFO, params, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

                Gson gson = new Gson();
                jsonModel_my = gson.fromJson(responseInfo.result, JsonModel_my.class);

                if (jsonModel_my.success) {

                    int len = jsonModel_my.getResult().size();

                    introduce.loadDataWithBaseURL(null, jsonModel_my.getResult().get(0).getContent(), "text/html", "utf-8", null);

                    if (len==2) {
                        mission_content.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                        mission.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));
                    }else if (len==3) {
                        mission_content.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                        mission.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));
                        hope_content.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getContent()));
                        hope.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getTitle()));
                    }
                    else if (len==4){
                        mission_content.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getContent()));
                        mission.setText(Html.fromHtml(jsonModel_my.getResult().get(1).getTitle()));
                        hope_content.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getContent()));
                        hope.setText(Html.fromHtml(jsonModel_my.getResult().get(2).getTitle()));
                        value_content.setText(Html.fromHtml(jsonModel_my.getResult().get(len - 1).getContent()));
                        value.setText(Html.fromHtml(jsonModel_my.getResult().get(len - 1).getTitle()));
                    }
                }
            }

            @Override
            public void onFailure(HttpException error, String msg) {
                ToastUtils.showShort(getApplicationContext(), "网络异常！");
            }
        });

    }

    private void initview() {
        initTopBar("平台简介");
        introduce = (WebView)findViewById(R.id.introduce);
        mission = (TextView)findViewById(R.id.mission);
        mission_content = (TextView)findViewById(R.id.mission_content);
        hope = (TextView)findViewById(R.id.hope);
        hope_content = (TextView)findViewById(R.id.hope_content);
        value = (TextView)findViewById(R.id.value);
        value_content = (TextView)findViewById(R.id.value_content);
    }
}
